package com.anjbo.controller.homepage;

import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.collections.MapUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.anjbo.common.RespDataObject;
import com.anjbo.common.RespHelper;
import com.anjbo.common.RespStatusEnum;
import com.anjbo.service.house.HouseService;
import com.anjbo.service.order.ProductConfigurationService;
import com.anjbo.utils.LoginCacheUtil;

/**
 * c端房产首页
 * @author Administrator
 *
 */
@RequestMapping("/app/house/homePage")
@Controller
public class HouseHomePageController {
	@Resource
	private HouseService houseService;
	
	@Resource
	private ProductConfigurationService productConfigurationService;
	
	/**
	 * 查用户我的资产和总涨幅
	 * @param request
	 * @param param
	 * @return
	 */
	@RequestMapping("/selectHouseAsset")
	@ResponseBody
	public RespDataObject<Map<String, Object>> selectHouseAsset(
			HttpServletRequest request, @RequestBody Map<String, Object> param) {
		RespDataObject<Map<String,Object>> resp = new RespDataObject<Map<String, Object>>();
		try {
			param.put("uid", LoginCacheUtil.getUid(MapUtils.getString(param, "sid"), MapUtils.getString(param, "deviceId")));
			Map<String, Object> resultMap = houseService.selectHouseAssetByIndex(param);
			if (resultMap == null) {
				resultMap = new HashMap<String, Object>();
			}
			Map<String,Object> configurationMap = productConfigurationService.selectStateByName("C端首页贷款入口");
			if (configurationMap != null && !configurationMap.isEmpty()) {
				resultMap.putAll(configurationMap);
			} else {
				resultMap.put("isShow","0");
			}
			if(configurationMap.get("showCities") == null || "".equals("showCities")){
				resultMap.put("showCities","深圳, 广州, 东莞, 惠州, 厦门");
			}
			if (MapUtils.getDouble(resultMap, "sumPrice") == null || MapUtils.getDouble(resultMap, "appreciation") == null) {
				resultMap.put("sumPrice", 0);
				resultMap.put("appreciation", 0);
			} else {
				double sumPrice = MapUtils.getDouble(resultMap, "sumPrice");
				double appreciation = MapUtils.getDouble(resultMap, "appreciation");
				resultMap.put("sumPrice", sumPrice);
				resultMap.put("appreciation", appreciation);
			}
			List<String> list= productConfigurationService.selectProCityList();
            HashSet<String> citySet = new HashSet<String>();
            for(String city:list){
                String[] split = city.split(",");
                for(String s:split){
                    citySet.add(s.trim());
                }
            }
            ArrayList<String> arrayList = new ArrayList<String>(citySet);
            resultMap.put("showCities",arrayList);
			resp.setData(resultMap);
			resp.setCode(RespStatusEnum.SUCCESS.getCode());
			resp.setMsg(RespStatusEnum.SUCCESS.getMsg());
		} catch (Exception e) {
            RespHelper.setFailDataObject(resp,null, RespStatusEnum.FAIL.getMsg());
            e.printStackTrace();
		}
		return resp;
	}
}
